\(\int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx\) [15]

   Optimal result
   Rubi [A] (verified)
   Mathematica [C] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [F]
   Maxima [A] (verification not implemented)
   Giac [B] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 13, antiderivative size = 72 \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=\frac {a \left (a^2+3 b^2\right ) x}{2 \left (a^2+b^2\right )^2}-\frac {b^3 \log (b \cos (x)+a \sin (x))}{\left (a^2+b^2\right )^2}-\frac {(b+a \cot (x)) \sin ^2(x)}{2 \left (a^2+b^2\right )} \]

[Out]

1/2*a*(a^2+3*b^2)*x/(a^2+b^2)^2-b^3*ln(b*cos(x)+a*sin(x))/(a^2+b^2)^2-1/2*(b+a*cot(x))*sin(x)^2/(a^2+b^2)

Rubi [A] (verified)

Time = 0.16 (sec) , antiderivative size = 72, normalized size of antiderivative = 1.00, number of steps used = 7, number of rules used = 6, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.462, Rules used = {3587, 755, 815, 649, 209, 266} \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=\frac {a x \left (a^2+3 b^2\right )}{2 \left (a^2+b^2\right )^2}-\frac {\sin ^2(x) (a \cot (x)+b)}{2 \left (a^2+b^2\right )}-\frac {b^3 \log (a \sin (x)+b \cos (x))}{\left (a^2+b^2\right )^2} \]

[In]

Int[Sin[x]^2/(a + b*Cot[x]),x]

[Out]

(a*(a^2 + 3*b^2)*x)/(2*(a^2 + b^2)^2) - (b^3*Log[b*Cos[x] + a*Sin[x]])/(a^2 + b^2)^2 - ((b + a*Cot[x])*Sin[x]^
2)/(2*(a^2 + b^2))

Rule 209

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(1/(Rt[a, 2]*Rt[b, 2]))*ArcTan[Rt[b, 2]*(x/Rt[a, 2])], x] /;
 FreeQ[{a, b}, x] && PosQ[a/b] && (GtQ[a, 0] || GtQ[b, 0])

Rule 266

Int[(x_)^(m_.)/((a_) + (b_.)*(x_)^(n_)), x_Symbol] :> Simp[Log[RemoveContent[a + b*x^n, x]]/(b*n), x] /; FreeQ
[{a, b, m, n}, x] && EqQ[m, n - 1]

Rule 649

Int[((d_) + (e_.)*(x_))/((a_) + (c_.)*(x_)^2), x_Symbol] :> Dist[d, Int[1/(a + c*x^2), x], x] + Dist[e, Int[x/
(a + c*x^2), x], x] /; FreeQ[{a, c, d, e}, x] &&  !NiceSqrtQ[(-a)*c]

Rule 755

Int[((d_) + (e_.)*(x_))^(m_)*((a_) + (c_.)*(x_)^2)^(p_), x_Symbol] :> Simp[(-(d + e*x)^(m + 1))*(a*e + c*d*x)*
((a + c*x^2)^(p + 1)/(2*a*(p + 1)*(c*d^2 + a*e^2))), x] + Dist[1/(2*a*(p + 1)*(c*d^2 + a*e^2)), Int[(d + e*x)^
m*Simp[c*d^2*(2*p + 3) + a*e^2*(m + 2*p + 3) + c*e*d*(m + 2*p + 4)*x, x]*(a + c*x^2)^(p + 1), x], x] /; FreeQ[
{a, c, d, e, m}, x] && NeQ[c*d^2 + a*e^2, 0] && LtQ[p, -1] && IntQuadraticQ[a, 0, c, d, e, m, p, x]

Rule 815

Int[(((d_.) + (e_.)*(x_))^(m_)*((f_.) + (g_.)*(x_)))/((a_) + (c_.)*(x_)^2), x_Symbol] :> Int[ExpandIntegrand[(
d + e*x)^m*((f + g*x)/(a + c*x^2)), x], x] /; FreeQ[{a, c, d, e, f, g}, x] && NeQ[c*d^2 + a*e^2, 0] && Integer
Q[m]

Rule 3587

Int[sec[(e_.) + (f_.)*(x_)]^(m_)*((a_) + (b_.)*tan[(e_.) + (f_.)*(x_)])^(n_), x_Symbol] :> Dist[1/(b*f), Subst
[Int[(a + x)^n*(1 + x^2/b^2)^(m/2 - 1), x], x, b*Tan[e + f*x]], x] /; FreeQ[{a, b, e, f, n}, x] && NeQ[a^2 + b
^2, 0] && IntegerQ[m/2]

Rubi steps \begin{align*} \text {integral}& = -\frac {\text {Subst}\left (\int \frac {1}{(a+x) \left (1+\frac {x^2}{b^2}\right )^2} \, dx,x,b \cot (x)\right )}{b} \\ & = -\frac {(b+a \cot (x)) \sin ^2(x)}{2 \left (a^2+b^2\right )}+\frac {b \text {Subst}\left (\int \frac {-2-\frac {a^2}{b^2}-\frac {a x}{b^2}}{(a+x) \left (1+\frac {x^2}{b^2}\right )} \, dx,x,b \cot (x)\right )}{2 \left (a^2+b^2\right )} \\ & = -\frac {(b+a \cot (x)) \sin ^2(x)}{2 \left (a^2+b^2\right )}+\frac {b \text {Subst}\left (\int \left (-\frac {2 b^2}{\left (a^2+b^2\right ) (a+x)}+\frac {-a^3-3 a b^2+2 b^2 x}{\left (a^2+b^2\right ) \left (b^2+x^2\right )}\right ) \, dx,x,b \cot (x)\right )}{2 \left (a^2+b^2\right )} \\ & = -\frac {b^3 \log (a+b \cot (x))}{\left (a^2+b^2\right )^2}-\frac {(b+a \cot (x)) \sin ^2(x)}{2 \left (a^2+b^2\right )}+\frac {b \text {Subst}\left (\int \frac {-a^3-3 a b^2+2 b^2 x}{b^2+x^2} \, dx,x,b \cot (x)\right )}{2 \left (a^2+b^2\right )^2} \\ & = -\frac {b^3 \log (a+b \cot (x))}{\left (a^2+b^2\right )^2}-\frac {(b+a \cot (x)) \sin ^2(x)}{2 \left (a^2+b^2\right )}+\frac {b^3 \text {Subst}\left (\int \frac {x}{b^2+x^2} \, dx,x,b \cot (x)\right )}{\left (a^2+b^2\right )^2}-\frac {\left (a b \left (a^2+3 b^2\right )\right ) \text {Subst}\left (\int \frac {1}{b^2+x^2} \, dx,x,b \cot (x)\right )}{2 \left (a^2+b^2\right )^2} \\ & = \frac {a \left (a^2+3 b^2\right ) x}{2 \left (a^2+b^2\right )^2}-\frac {b^3 \log (a+b \cot (x))}{\left (a^2+b^2\right )^2}-\frac {b^3 \log (\sin (x))}{\left (a^2+b^2\right )^2}-\frac {(b+a \cot (x)) \sin ^2(x)}{2 \left (a^2+b^2\right )} \\ \end{align*}

Mathematica [C] (verified)

Result contains complex when optimal does not.

Time = 0.33 (sec) , antiderivative size = 94, normalized size of antiderivative = 1.31 \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=\frac {2 a^3 x+6 a b^2 x-4 i b^3 x+4 i b^3 \arctan (\tan (x))+b \left (a^2+b^2\right ) \cos (2 x)-2 b^3 \log \left ((b \cos (x)+a \sin (x))^2\right )-a^3 \sin (2 x)-a b^2 \sin (2 x)}{4 \left (a^2+b^2\right )^2} \]

[In]

Integrate[Sin[x]^2/(a + b*Cot[x]),x]

[Out]

(2*a^3*x + 6*a*b^2*x - (4*I)*b^3*x + (4*I)*b^3*ArcTan[Tan[x]] + b*(a^2 + b^2)*Cos[2*x] - 2*b^3*Log[(b*Cos[x] +
 a*Sin[x])^2] - a^3*Sin[2*x] - a*b^2*Sin[2*x])/(4*(a^2 + b^2)^2)

Maple [A] (verified)

Time = 0.64 (sec) , antiderivative size = 97, normalized size of antiderivative = 1.35

method result size
default \(-\frac {b^{3} \ln \left (\tan \left (x \right ) a +b \right )}{\left (a^{2}+b^{2}\right )^{2}}+\frac {\frac {\left (-\frac {1}{2} a^{3}-\frac {1}{2} a \,b^{2}\right ) \tan \left (x \right )+\frac {a^{2} b}{2}+\frac {b^{3}}{2}}{\tan \left (x \right )^{2}+1}+\frac {b^{3} \ln \left (\tan \left (x \right )^{2}+1\right )}{2}+\frac {\left (a^{3}+3 a \,b^{2}\right ) \arctan \left (\tan \left (x \right )\right )}{2}}{\left (a^{2}+b^{2}\right )^{2}}\) \(97\)
risch \(\frac {i x b}{2 i a b +a^{2}-b^{2}}+\frac {x a}{4 i a b +2 a^{2}-2 b^{2}}+\frac {i {\mathrm e}^{2 i x}}{8 i b +8 a}-\frac {i {\mathrm e}^{-2 i x}}{8 \left (-i b +a \right )}+\frac {2 i b^{3} x}{a^{4}+2 a^{2} b^{2}+b^{4}}-\frac {b^{3} \ln \left ({\mathrm e}^{2 i x}+\frac {i b -a}{i b +a}\right )}{a^{4}+2 a^{2} b^{2}+b^{4}}\) \(145\)

[In]

int(sin(x)^2/(a+b*cot(x)),x,method=_RETURNVERBOSE)

[Out]

-b^3/(a^2+b^2)^2*ln(tan(x)*a+b)+1/(a^2+b^2)^2*(((-1/2*a^3-1/2*a*b^2)*tan(x)+1/2*a^2*b+1/2*b^3)/(tan(x)^2+1)+1/
2*b^3*ln(tan(x)^2+1)+1/2*(a^3+3*a*b^2)*arctan(tan(x)))

Fricas [A] (verification not implemented)

none

Time = 0.29 (sec) , antiderivative size = 94, normalized size of antiderivative = 1.31 \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=-\frac {b^{3} \log \left (2 \, a b \cos \left (x\right ) \sin \left (x\right ) - {\left (a^{2} - b^{2}\right )} \cos \left (x\right )^{2} + a^{2}\right ) - {\left (a^{2} b + b^{3}\right )} \cos \left (x\right )^{2} + {\left (a^{3} + a b^{2}\right )} \cos \left (x\right ) \sin \left (x\right ) - {\left (a^{3} + 3 \, a b^{2}\right )} x}{2 \, {\left (a^{4} + 2 \, a^{2} b^{2} + b^{4}\right )}} \]

[In]

integrate(sin(x)^2/(a+b*cot(x)),x, algorithm="fricas")

[Out]

-1/2*(b^3*log(2*a*b*cos(x)*sin(x) - (a^2 - b^2)*cos(x)^2 + a^2) - (a^2*b + b^3)*cos(x)^2 + (a^3 + a*b^2)*cos(x
)*sin(x) - (a^3 + 3*a*b^2)*x)/(a^4 + 2*a^2*b^2 + b^4)

Sympy [F]

\[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=\int \frac {\sin ^{2}{\left (x \right )}}{a + b \cot {\left (x \right )}}\, dx \]

[In]

integrate(sin(x)**2/(a+b*cot(x)),x)

[Out]

Integral(sin(x)**2/(a + b*cot(x)), x)

Maxima [A] (verification not implemented)

none

Time = 0.31 (sec) , antiderivative size = 120, normalized size of antiderivative = 1.67 \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=-\frac {b^{3} \log \left (a \tan \left (x\right ) + b\right )}{a^{4} + 2 \, a^{2} b^{2} + b^{4}} + \frac {b^{3} \log \left (\tan \left (x\right )^{2} + 1\right )}{2 \, {\left (a^{4} + 2 \, a^{2} b^{2} + b^{4}\right )}} + \frac {{\left (a^{3} + 3 \, a b^{2}\right )} x}{2 \, {\left (a^{4} + 2 \, a^{2} b^{2} + b^{4}\right )}} - \frac {a \tan \left (x\right ) - b}{2 \, {\left ({\left (a^{2} + b^{2}\right )} \tan \left (x\right )^{2} + a^{2} + b^{2}\right )}} \]

[In]

integrate(sin(x)^2/(a+b*cot(x)),x, algorithm="maxima")

[Out]

-b^3*log(a*tan(x) + b)/(a^4 + 2*a^2*b^2 + b^4) + 1/2*b^3*log(tan(x)^2 + 1)/(a^4 + 2*a^2*b^2 + b^4) + 1/2*(a^3
+ 3*a*b^2)*x/(a^4 + 2*a^2*b^2 + b^4) - 1/2*(a*tan(x) - b)/((a^2 + b^2)*tan(x)^2 + a^2 + b^2)

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 148 vs. \(2 (68) = 136\).

Time = 0.26 (sec) , antiderivative size = 148, normalized size of antiderivative = 2.06 \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx=-\frac {a b^{3} \log \left ({\left | a \tan \left (x\right ) + b \right |}\right )}{a^{5} + 2 \, a^{3} b^{2} + a b^{4}} + \frac {b^{3} \log \left (\tan \left (x\right )^{2} + 1\right )}{2 \, {\left (a^{4} + 2 \, a^{2} b^{2} + b^{4}\right )}} + \frac {{\left (a^{3} + 3 \, a b^{2}\right )} x}{2 \, {\left (a^{4} + 2 \, a^{2} b^{2} + b^{4}\right )}} - \frac {b^{3} \tan \left (x\right )^{2} + a^{3} \tan \left (x\right ) + a b^{2} \tan \left (x\right ) - a^{2} b}{2 \, {\left (a^{4} + 2 \, a^{2} b^{2} + b^{4}\right )} {\left (\tan \left (x\right )^{2} + 1\right )}} \]

[In]

integrate(sin(x)^2/(a+b*cot(x)),x, algorithm="giac")

[Out]

-a*b^3*log(abs(a*tan(x) + b))/(a^5 + 2*a^3*b^2 + a*b^4) + 1/2*b^3*log(tan(x)^2 + 1)/(a^4 + 2*a^2*b^2 + b^4) +
1/2*(a^3 + 3*a*b^2)*x/(a^4 + 2*a^2*b^2 + b^4) - 1/2*(b^3*tan(x)^2 + a^3*tan(x) + a*b^2*tan(x) - a^2*b)/((a^4 +
 2*a^2*b^2 + b^4)*(tan(x)^2 + 1))

Mupad [B] (verification not implemented)

Time = 12.05 (sec) , antiderivative size = 126, normalized size of antiderivative = 1.75 \[ \int \frac {\sin ^2(x)}{a+b \cot (x)} \, dx={\cos \left (x\right )}^2\,\left (\frac {b}{2\,\left (a^2+b^2\right )}-\frac {a\,\mathrm {tan}\left (x\right )}{2\,\left (a^2+b^2\right )}\right )-\frac {b^3\,\ln \left (b+a\,\mathrm {tan}\left (x\right )\right )}{{\left (a^2+b^2\right )}^2}+\frac {\ln \left (\mathrm {tan}\left (x\right )-\mathrm {i}\right )\,\left (2\,b+a\,1{}\mathrm {i}\right )}{4\,\left (-a^2+a\,b\,2{}\mathrm {i}+b^2\right )}+\frac {\ln \left (\mathrm {tan}\left (x\right )+1{}\mathrm {i}\right )\,\left (a+b\,2{}\mathrm {i}\right )}{4\,\left (-a^2\,1{}\mathrm {i}+2\,a\,b+b^2\,1{}\mathrm {i}\right )} \]

[In]

int(sin(x)^2/(a + b*cot(x)),x)

[Out]

cos(x)^2*(b/(2*(a^2 + b^2)) - (a*tan(x))/(2*(a^2 + b^2))) - (b^3*log(b + a*tan(x)))/(a^2 + b^2)^2 + (log(tan(x
) - 1i)*(a*1i + 2*b))/(4*(a*b*2i - a^2 + b^2)) + (log(tan(x) + 1i)*(a + b*2i))/(4*(2*a*b - a^2*1i + b^2*1i))